package com.fengycx.app;


import cn.dev33.satoken.annotation.SaIgnore;
import com.fengycx.pojo.domain.Customer;
import com.fengycx.pojo.domain.CustomerCar;
import com.fengycx.result.R;
import com.fengycx.service.ICustomerCarService;
import com.fengycx.service.ICustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

@Tag(name = "App客户对象",description = "App客户对象")
@RestController
@RequestMapping("/app/customer")
@Validated
public class AppCustomerController {

    @Autowired
    private ICustomerService customerService;

    @Autowired
    private ICustomerCarService carService;

    @PostMapping("/appRegister/{code}")
    @SaIgnore
    public R<Boolean> appRegister(@PathVariable("code")  @NotBlank(message = "参数不能为空") String code){
        customerService.code2OpenId(code);
        return R.success();
    }


    @Operation( summary= "保存CustomerCar",description = "基础对象保存接口")
    @Parameter(name = "customerCar",description = "保存的对象",required = true)
    @PostMapping("/car/add")
    public R<Boolean> addCar(@RequestBody @Valid CustomerCar customerCar){
        carService.addCar(customerCar);
        return R.success();
    }

    @GetMapping("/car/list")
    public R<List<CustomerCar>> customerCarList(){
        return R.success( carService.getCustomerCarList());
    }

}
